﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using YGame.Base;
using System.Diagnostics;
using System.Runtime.Serialization.Json;

namespace YGame.GameServer
{

	public class GameServerProvider : IGameServerProvider
	{
		public event ReceiveMessageHandle ReceiveMessage;

        public event EventHandler Login;
        public event EventHandler Logout;

		public GameServerProvider()
		{
		}


		public bool Start()
		{
			YGame.Base.ServerGlobal.GatewayConnect.ReceiveData += _gatewayConnect_ReceiveData;
			return true;
		}


		public bool Stop()
		{
			YGame.Base.ServerGlobal.GatewayConnect.ReceiveData -= _gatewayConnect_ReceiveData;
			return true;
		}

		/// <summary>
		/// 网关收到消息处理
		/// </summary>
		/// <param name="connect"></param>
		/// <param name="e"></param>
		void _gatewayConnect_ReceiveData(IGatewayConnect connect, ReceiveDataArgs e)
		{
			// 解包
			ReceiveMessageArgs msgArgs = new ReceiveMessageArgs();
			msgArgs.Message = BaseMessage.Create(e.Data);

			// 分配消息
			if (ReceiveMessage != null)
			{
				ReceiveMessage(this, msgArgs);
			}
		}

        
	}




}
